package cn.edu.hpu.web;


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.hpu.dao.IdeaDao;
import cn.edu.hpu.entity.Employee;
import cn.edu.hpu.entity.Idea;
import cn.edu.hpu.entity.Project;
import cn.edu.hpu.utitl.TimeUtitl;
import cn.edu.hpu.utitl.UUIDUtitl;

public class NewIdeaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		String ititle = request.getParameter("ititle");
		String icontent = request.getParameter("icontent");
		String iid = UUIDUtitl.getUUID();
		String ictime = TimeUtitl.getTime();
		HttpSession session = request.getSession();
		Employee e =(Employee) session.getAttribute("employee");
		String eid = e.getEid();
		Project p = (Project)session.getAttribute("project");
		String pid = p.getPid();
		Idea i = new Idea();
		i.setEid(eid);
		i.setIcontent(icontent);
		i.setIctime(ictime);
		i.setIid(iid);
		i.setItitle(ititle);
		i.setPid(pid);
		IdeaDao id = new IdeaDao();
		try {
			id.insertAIdea(iid, ititle, icontent, ictime, pid, eid);
			/*List<Idea> list =(List<Idea>) session.getAttribute("ilist");
			if(list == null){
				list = new ArrayList<Idea>();
			}
			list.add(i);*/
			List<Idea> list = id.findAllIdea();
			session.setAttribute("ilist", list);
			request.getRequestDispatcher("/WEB-INF/views/idea.jsp").forward(request, response);
		} catch (Exception e2) {
			response.sendRedirect("/WEB-INF/views/idea.jsp");
		}
	}
}
